package picture;

import javax.swing.*;
import java.awt.*;

public class ButtonUtils {
    public static JButton createIconButton(String iconPath, int width, int height) {
        JButton button = new JButton();
        try {
            ImageIcon icon = new ImageIcon(ButtonUtils.class.getResource("/" +iconPath));
            Image img = icon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH);
            button.setIcon(new ImageIcon(img));
            styleButton(button);
        } catch (Exception e) {
            System.out.println("无法加载按钮图标: " + e.getMessage());
        }
        return button;
    }

    private static void styleButton(JButton button) {
        button.setBorderPainted(false);
        button.setContentAreaFilled(false);
        button.setFocusPainted(false);
        button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    }
}
